/* eslint-disable import/no-anonymous-default-export */
/* eslint-disable jsx-a11y/anchor-is-valid */

import "./style.scss";
import React, {
  useRef,
  useState,
  useEffect,
  useContext,
  useCallback,
} from "react";
import {
  Avatar,
  Space,
  Radio,
  Input,
  DatePicker,
  Select,
  Switch,
  Button,
  message,
  Form,
  Spin,
  Popconfirm,
} from "antd";
import {
  UserOutlined,
  WechatOutlined,
  PlusCircleOutlined,
  FilePdfOutlined,
  DeleteOutlined,
} from "@ant-design/icons";
import { putFile } from "../../api/oss";
import { DateFormat } from "../../api/config";
import dayjs from "dayjs";
import customParseFormat from "dayjs/plugin/customParseFormat";
import { UserContext } from "../../store/user";
import { useNavigate, useLocation } from "react-router";
import {
  postUserEdit,
  postAddUserWorkExperience,
  postAddUserEducation,
  postAddExpectedJob,
} from "../../api/recruit-manage";
import { getUserQuery } from "../../api/profile";

dayjs.extend(customParseFormat);

// <DeleteOutlined />

const { TextArea } = Input;
const { RangePicker } = DatePicker;

const MaxDate = new Date();
const MaxDateYear = MaxDate.getFullYear();
const MaxDateMonth = `${MaxDate.getMonth() + 1}`.padStart(2, "0");
const MaxDateDate = `${MaxDate.getDate()}`.padStart(2, "0");

export default () => {
  const navigate = useNavigate();
  const location = useLocation();

  // console.log('当前页面路径: ', location)
  const [wordPdfUrl, setWordPdfUrl] = useState(""); // 附件简历url http://ai-ping-web.oss-cn-shanghai.aliyuncs.com/dird452b5d9-4cb6-4152-b3c3-7dd833e6ecdequaternion.pdf
  const wordInputRef = useRef();

  const ji_beng_xingxiRef = useRef();
  const qiuzhi_yixiangRef = useRef();
  const jiaoyuRef = useRef();
  const gongzuoRef = useRef();

  const [loading, setLoading] = useState(false);

  const [form] = Form.useForm();

  const ctx = useContext(UserContext);
  // console.log('ctx=', ctx)
  const user = ctx.user;

  const [messageApi, contextHolder] = message.useMessage();

  // 编辑资料页面初始赋值
  useEffect(() => {
    const [_, ids] = location.pathname.match(/\/([^\/]*)$/);

    (async () => {
      let res = await getUserQuery({ id: ids, loginBizId: user.loginBizId });
      console.log("当前简历资料页数据: ", res);
      setUserName(res.result?.userName ?? "");
      setGender(res.result?.gender ?? 0);
      setBirthDate(res.result?.birthDate ?? "");
      setEmail(res.result?.email ?? "");
      setWechatId(res.result?.wechatId);
      setJobPosition(res.result?.jobPosition);
      setWorkingYears(res.result?.workingYears);
      setWordPdfUrl(res.result?.attachmentUrl ?? "");
      setMobile(res.result?.loginBizId ?? "");

      let _userEducationArr = (res.result?.userEducationList ?? []).map(
        (itemObj) => ({
          ...itemObj,
          keyId: crypto.randomUUID(),
        })
      );

      if (_userEducationArr.length < 1) {
        _userEducationArr = [
          {
            keyId: crypto.randomUUID(),
            schoolName: "",
            majorName: "",
            educationLevel: "",
            enrollmentDate: "",
            graduationDate: "",
          },
        ];
      }

      setUserEducationArr(_userEducationArr);

      let _workExperienceArr = (res.result?.userWorkExperiencList ?? []).map(
        (itemObj) => ({
          ...itemObj,
          keyId: crypto.randomUUID(),
        })
      );

      if (_workExperienceArr.length < 1) {
        _workExperienceArr = [
          {
            keyId: crypto.randomUUID(),
            companyName: "",
            jobPosition: "",
            jobStartTime: "",
            jobEndTime: "",
            jobDescription: "",
            isCurrentEmployed: 0,
          },
        ];
      }

      setWorkExperienceArr(_workExperienceArr);

      let _userExpectedJobList = (res.result?.userExpectedJobList ?? []).map(
        (itemObj) => ({
          ...itemObj,
          keyId: crypto.randomUUID(),
        })
      );

      if (_userExpectedJobList.length < 1) {
        _userExpectedJobList = [
          {
            keyId: crypto.randomUUID(),
            expectedJobTitle: "",
            expectedJobCategory: "",
            expectedJobLocation: "",
            expectedJobIsRemoted: 0,
            expectedJobMinSalary: 0,
            expectedJobMaxSalary: 0,
            expectedJobSalaryRange: "",
          },
        ];
      }

      setExpectedJobArr(_userExpectedJobList);
    })();
  }, []);

  // 基本信息
  const [avartarUrl, setAvartarUrl] = useState("");
  const [userName, setUserName] = useState("");
  const [gender, setGender] = useState(0);
  const [birthDate, setBirthDate] = useState("");
  const [mobile, setMobile] = useState("");
  const [email, setEmail] = useState("");
  const [wechatId, setWechatId] = useState("");
  const [jobPosition, setJobPosition] = useState("");
  const [workingYears, setWorkingYears] = useState("");

  const [expectedJobArr, setExpectedJobArr] = useState([
    {
      keyId: crypto.randomUUID(),
      expectedJobTitle: "",
      expectedJobCategory: "",
      expectedJobLocation: "",
      expectedJobIsRemoted: 0,
      expectedJobMinSalary: 0,
      expectedJobMaxSalary: 0,
      expectedJobSalaryRange: "",
    },
  ]);

  const [userEducationArr, setUserEducationArr] = useState([
    {
      keyId: crypto.randomUUID(),
      schoolName: "",
      majorName: "",
      educationLevel: "",
      enrollmentDate: "",
      graduationDate: "",
    },
  ]);

  // 工作经历
  const [workExperienceArr, setWorkExperienceArr] = useState([
    {
      keyId: crypto.randomUUID(),
      companyName: "",
      jobPosition: "",
      jobStartTime: "",
      jobEndTime: "",
      jobDescription: "",
      isCurrentEmployed: 0,
    },
  ]);

  // type, 头像还是附件简历
  const handleFileUpload = useCallback((file, type) => {
    (async () => {
      let href = await putFile(file);
      if (type === "avatar") {
        setAvartarUrl(href);
      } else {
        setWordPdfUrl(href);
      }
    })();
  }, []);

  // 期望城市select
  const onCityChange = (index, val) => {
    let nextArr = [...expectedJobArr];
    nextArr[index].expectedJobLocation = val;
    setExpectedJobArr(nextArr);
  };

  return (
    <Spin spinning={loading}>
      <div className="bg-gray-50 min-h-screen edit-resume-page">
        {contextHolder}
        <div className="max-w-4xl mx-auto px-4 py-8">
          <div className="flex justify-between items-center mb-6">
            <div>
              <h1 className="text-2xl font-bold text-gray-800">编辑简历</h1>
              <p className="text-gray-500 mt-1">
                完善您的简历信息，提高求职成功率
              </p>
            </div>
            <div className="flex space-x-3">
              <button className="hidden flex items-center px-4 py-2 border border-gray-300 text-gray-700 bg-white rounded-button hover:bg-gray-50 whitespace-nowrap">
                保存
              </button>
              <button className="hidden flex items-center px-4 py-2 border border-gray-300 text-gray-700 bg-white rounded-button hover:bg-gray-50 whitespace-nowrap">
                预览
              </button>
            </div>
          </div>
          <Form form={form}>
            <div
              ref={ji_beng_xingxiRef}
              className="bg-white rounded-lg shadow-sm p-6 mb-6"
            >
              <div className="flex justify-between items-center mb-4">
                <h2 className="text-lg font-semibold text-gray-800 flex items-center">
                  <span className="w-6 h-6 flex items-center justify-center mr-2 text-primary">
                    <i className="ri-user-3-line"></i>
                  </span>
                  基本信息
                </h2>
                {/* <button
                type="button"
                className="w-6 h-6 flex items-center justify-center text-gray-500 hover:text-gray-700"
              >
                <i className="ri-arrow-up-s-line"></i>
              </button> */}
              </div>
              <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div className="md:col-span-2 flex flex-col items-center">
                  {avartarUrl ? (
                    <img src={avartarUrl} width={128} />
                  ) : (
                    <Avatar size={128} icon={<UserOutlined />} />
                  )}

                  <span className="block text-sm text-[#1677ff] mt-2 relative cursor-pointer">
                    点击上传头像{" "}
                    <input
                      onChange={(e) => {
                        handleFileUpload(e.target.files[0], "avatar");
                        e.target.value = "";
                      }}
                      accept=".jpg, .jpeg, .png"
                      className="opacity-0 cursor-pointer absolute left-0 top-0 right-0"
                      type="file"
                    />
                  </span>
                </div>
                <div>
                  <label className="block text-sm font-medium text-gray-700 mb-1">
                    姓名 <span className="text-red-500">*</span>
                  </label>
                  <Input
                    type="text"
                    className="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary"
                    placeholder="请输入您的姓名"
                    value={userName}
                    onChange={(ev) => {
                      setUserName(ev.target.value.trim());
                    }}
                  />
                </div>
                <div>
                  <label className="block text-sm font-medium text-gray-700 mb-1">
                    性别
                  </label>
                  <div className="flex space-x-6 mt-1">
                    <Radio.Group
                      value={gender}
                      onChange={(ev) => {
                        setGender(ev.target.value);
                      }}
                      block
                      options={[
                        { label: "男", value: 0 },
                        { label: "女", value: 1 },
                      ]}
                    />
                  </div>
                </div>
                <div>
                  <label className="block text-sm font-medium text-gray-700 mb-1">
                    出生日期
                  </label>
                  <div className="relative">
                    <DatePicker
                      size="large"
                      value={birthDate ? dayjs(birthDate) : ""}
                      style={{ width: "100%" }}
                      onChange={(_, dateString) => {
                        setBirthDate(dateString);
                      }}
                      format={DateFormat}
                      maxDate={dayjs(
                        `${MaxDateYear}-${MaxDateMonth}-${MaxDateDate}`,
                        DateFormat
                      )}
                    />
                  </div>
                </div>
                <div>
                  <label className="block text-sm font-medium text-gray-700 mb-1">
                    联系电话 <span className="text-red-500">*</span>
                  </label>
                  <input
                    type="tel"
                    className="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary"
                    placeholder="请输入您的联系电话"
                    value={mobile}
                    onChange={(ev) => {
                      setMobile(ev.target.value.trim().replace(/\D/g, ""));
                    }}
                  />
                </div>
                <div>
                  <label className="block text-sm font-medium text-gray-700 mb-1">
                    电子邮箱 <span className="text-red-500">*</span>
                  </label>
                  <input
                    type="email"
                    className="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary"
                    placeholder="请输入您的电子邮箱"
                    value={email}
                    onChange={(ev) => {
                      setEmail(ev.target.value.trim());
                    }}
                  />
                </div>
                <div>
                  <label className="block text-sm font-medium text-gray-700 mb-1">
                    微信号
                  </label>
                  <div className="relative">
                    <Input
                      size="large"
                      placeholder=""
                      value={wechatId}
                      onChange={(ev) => {
                        setWechatId(ev.target.value.trim());
                      }}
                      prefix={<WechatOutlined />}
                    />
                  </div>
                </div>
                <div>
                  <label className="block text-sm font-medium text-gray-700 mb-1">
                    应聘岗位 <span className="text-red-500">*</span>
                  </label>
                  <input
                    className="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary"
                    placeholder="请输入应聘岗位"
                    value={jobPosition}
                    onChange={(ev) => {
                      setJobPosition(ev.target.value.trim());
                    }}
                  />
                </div>
                <div>
                  <label className="block text-sm font-medium text-gray-700 mb-1">
                    工作经验(单位: 年)
                  </label>
                  <div className="relative">
                    <Input
                      size="large"
                      value={workingYears}
                      placeholder="请输入数字"
                      onChange={(ev) => {
                        setWorkingYears(
                          ev.target.value.trim().replace(/\D/g, "")
                        );
                      }}
                    />
                  </div>
                </div>
              </div>
            </div>
            <div
              ref={qiuzhi_yixiangRef}
              className="bg-white rounded-lg shadow-sm p-6 mb-6"
            >
              <div className="flex justify-between items-center mb-4">
                <h2 className="text-lg font-semibold text-gray-800 flex items-center">
                  <span className="w-6 h-6 flex items-center justify-center mr-2 text-primary">
                    <i className="ri-briefcase-4-line"></i>
                  </span>
                  求职意向
                </h2>
                <Button shape="circle" icon={<PlusCircleOutlined />} />
              </div>
              {expectedJobArr.map((rowObj, index) => (
                <div
                  key={rowObj.keyId}
                  className="border border-gray-200 rounded-lg p-4 mb-4"
                >
                  <div className="grid grid-cols-1 md:grid-cols-2 gap-6">
                    <div>
                      <label className="block text-sm font-medium text-gray-700 mb-1">
                        期望职位 <span className="text-red-500">*</span>
                      </label>
                      <input
                        type="text"
                        className="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary"
                        placeholder="请输入期望职位"
                        onChange={(ev) => {
                          let nextArr = [...expectedJobArr];
                          nextArr[index].expectedJobTitle =
                            ev.target.value.trim();
                          setExpectedJobArr(nextArr);
                        }}
                        value={rowObj.expectedJobTitle}
                      />
                    </div>
                    <div>
                      <label className="block text-sm font-medium text-gray-700 mb-1">
                        期望薪资
                      </label>
                      <div className="relative">
                        <Select
                          value={rowObj.expectedJobSalaryRange}
                          style={{ width: "100%" }}
                          size="large"
                          onChange={(val) => {
                            let nextArr = [...expectedJobArr];
                            nextArr[index].expectedJobSalaryRange = val;
                            setExpectedJobArr(nextArr);
                          }}
                          options={[
                            { value: "面议", label: "面议" },
                            { value: "3k-5k", label: "3k-5k" },
                            { value: "5k-8k", label: "5k-8k" },
                            { value: "8k-12k", label: "8k-12k" },
                            { value: "12k-15k", label: "12k-15k" },
                            { value: "15k-20k", label: "15k-20k" },
                            { value: "20k-30k", label: "20k-30k" },
                            { value: "30k以上", label: "30k以上" },
                          ]}
                        />
                      </div>
                    </div>
                    <div>
                      <label className="block text-sm font-medium text-gray-700 mb-1">
                        期望城市
                      </label>
                      <div className="relative">
                        <Select
                          value={rowObj.expectedJobLocation}
                          style={{ width: "100%" }}
                          onChange={(val) => {
                            // console.log('变换城市: ', val)
                            onCityChange(index, val);
                          }}
                          options={[
                            { value: "北京", label: "北京" },
                            { value: "上海", label: "上海" },
                            { value: "杭州", label: "杭州" },
                            { value: "南京", label: "南京" },
                            { value: "苏州", label: "苏州" },
                            { value: "宁波", label: "宁波" },
                            { value: "广州", label: "广州" },
                            { value: "深圳", label: "深圳" },
                            { value: "大连", label: "大连" },
                          ]}
                        />
                      </div>
                    </div>
                    <div>
                      <label className="block text-sm font-medium text-gray-700 mb-1">
                        工作类型
                      </label>
                      <div className="flex space-x-6 mt-1">
                        <Radio.Group
                          value={rowObj.expectedJobCategory}
                          onChange={(ev) => {
                            // console.log('变换工作类型: ', ev)
                            let nextArr = [...expectedJobArr];
                            nextArr[index].expectedJobCategory =
                              ev.target.value;
                            setExpectedJobArr(nextArr);
                          }}
                          block
                          options={[
                            { label: "全职", value: "全职" },
                            { label: "兼职", value: "兼职" },
                            { label: "实习", value: "实习" },
                          ]}
                        />
                      </div>
                    </div>
                  </div>
                  <div className="flex justify-end mt-3">
                    {expectedJobArr.length > 1 && (
                      <button
                        type="button"
                        className="flex items-center px-3 py-1 text-sm text-red-500 hover:text-red-700"
                        onClick={() => {
                          let nextArr = [...expectedJobArr];
                          nextArr.splice(index, 1);
                          setExpectedJobArr(nextArr);
                        }}
                      >
                        删除
                      </button>
                    )}
                  </div>
                </div>
              ))}
              <button
                type="button"
                className="flex items-center px-4 py-2 text-primary border border-primary rounded-button hover:bg-primary/5 whitespace-nowrap"
                onClick={() => {
                  let nextArr = [...expectedJobArr];
                  nextArr.push({
                    keyId: crypto.randomUUID(),
                    expectedJobTitle: "",
                    expectedJobCategory: "",
                    expectedJobLocation: "",
                    expectedJobIsRemoted: 0,
                    expectedJobMinSalary: 0,
                    expectedJobMaxSalary: 0,
                  });
                  setExpectedJobArr(nextArr);
                }}
              >
                添加求职期望
              </button>
            </div>
            <div
              ref={jiaoyuRef}
              className="bg-white rounded-lg shadow-sm p-6 mb-6"
            >
              <div className="flex justify-between items-center mb-4">
                <h2 className="text-lg font-semibold text-gray-800 flex items-center">
                  <span className="w-6 h-6 flex items-center justify-center mr-2 text-primary">
                    <i className="ri-graduation-cap-line"></i>
                  </span>
                  教育经历
                </h2>
                <Button shape="circle" icon={<PlusCircleOutlined />} />
              </div>
              {userEducationArr.map((rowObj, index) => (
                <div
                  key={rowObj.keyId}
                  className="border border-gray-200 rounded-lg p-4 mb-4"
                >
                  <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div>
                      <label className="block text-sm font-medium text-gray-700 mb-1">
                        学校名称
                      </label>
                      <input
                        type="text"
                        className="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary"
                        value={rowObj.schoolName}
                        onChange={(ev) => {
                          let nextArr = [...userEducationArr];
                          nextArr[index].schoolName = ev.target.value.trim();
                          setUserEducationArr(nextArr);
                        }}
                      />
                    </div>
                    <div>
                      <label className="block text-sm font-medium text-gray-700 mb-1">
                        专业名称
                      </label>
                      <input
                        type="text"
                        className="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary"
                        value={rowObj.majorName}
                        onChange={(ev) => {
                          let nextArr = [...userEducationArr];
                          nextArr[index].majorName = ev.target.value.trim();
                          setUserEducationArr(nextArr);
                        }}
                      />
                    </div>
                    <div>
                      <label className="block text-sm font-medium text-gray-700 mb-1">
                        学历
                      </label>
                      <div className="relative">
                        <Select
                          value={rowObj.educationLevel}
                          onChange={(val) => {
                            let nextArr = [...userEducationArr];
                            nextArr[index].educationLevel = val;
                            setUserEducationArr(nextArr);
                          }}
                          size="large"
                          allowClear
                          style={{ width: "100%" }}
                          options={[
                            { value: "高中", label: "高中" },
                            { value: "大专", label: "大专" },
                            { value: "本科", label: "本科" },
                            { value: "硕士", label: "硕士" },
                            { value: "博士", label: "博士" },
                          ]}
                        />
                      </div>
                    </div>
                    <div>
                      <label className="block text-sm font-medium text-gray-700 mb-1">
                        入学时间-毕业时间
                      </label>
                      <div className="flex items-center">
                        {/* dayjs(rowObj.enrollmentDate), dayjs(rowObj.graduationDate)  */}
                        <RangePicker
                          size="large"
                          value={[
                            rowObj.enrollmentDate
                              ? dayjs(rowObj.enrollmentDate)
                              : "",
                            rowObj.graduationDate
                              ? dayjs(rowObj.graduationDate)
                              : "",
                          ]}
                          style={{ width: "100%" }}
                          onChange={(dates, dateStrings) => {
                            // console.log('==>', dates,', ',  dateStrings)
                            let nextArr = [...userEducationArr];
                            nextArr[index].enrollmentDate = dateStrings[0];
                            nextArr[index].graduationDate = dateStrings[1];
                            setUserEducationArr(nextArr);
                          }}
                          format={DateFormat}
                        />
                      </div>
                    </div>
                  </div>
                  <div className="flex justify-end mt-3">
                    {userEducationArr.length > 1 && (
                      <button
                        type="button"
                        className="flex items-center px-3 py-1 text-sm text-red-500 hover:text-red-700"
                        onClick={() => {
                          let nextArr = [...userEducationArr];
                          nextArr.splice(index, 1);
                          setUserEducationArr(nextArr);
                        }}
                      >
                        删除
                      </button>
                    )}
                  </div>
                </div>
              ))}
              <button
                type="button"
                className="flex items-center px-4 py-2 text-primary border border-primary rounded-button hover:bg-primary/5 whitespace-nowrap"
                onClick={() => {
                  let nextArr = [...userEducationArr];
                  nextArr.push({
                    keyId: crypto.randomUUID(),
                    schoolName: "",
                    majorName: "",
                    educationLevel: "",
                    enrollmentDate: "",
                    graduationDate: "",
                  });
                  setUserEducationArr(nextArr);
                }}
              >
                添加教育经历
              </button>
            </div>
            <div
              ref={gongzuoRef}
              className="bg-white rounded-lg shadow-sm p-6 mb-6 pb-[60px]"
            >
              <div className="flex justify-between items-center mb-4">
                <h2 className="text-lg font-semibold text-gray-800 flex items-center">
                  <span className="w-6 h-6 flex items-center justify-center mr-2 text-primary">
                    <i className="ri-building-4-line"></i>
                  </span>
                  工作经历
                </h2>
                <Button shape="circle" icon={<PlusCircleOutlined />} />
              </div>
              {workExperienceArr.map((rowObj, index) => (
                <div
                  key={rowObj.keyId}
                  className="border border-gray-200 rounded-lg p-4 mb-4"
                >
                  <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
                    <div>
                      <label className="block text-sm font-medium text-gray-700 mb-1">
                        公司名称
                      </label>
                      <input
                        type="text"
                        className="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary"
                        value={rowObj.companyName}
                        onChange={(ev) => {
                          let nextArr = [...workExperienceArr];
                          nextArr[index].companyName = ev.target.value.trim();
                          setWorkExperienceArr(nextArr);
                        }}
                      />
                    </div>
                    <div>
                      <label className="block text-sm font-medium text-gray-700 mb-1">
                        职位名称
                      </label>
                      <input
                        type="text"
                        className="w-full px-3 py-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-primary/20 focus:border-primary"
                        value={rowObj.jobPosition}
                        onChange={(ev) => {
                          let nextArr = [...workExperienceArr];
                          nextArr[index].jobPosition = ev.target.value.trim();
                          setWorkExperienceArr(nextArr);
                        }}
                      />
                    </div>
                    <div className="md:col-span-2">
                      <label className="block text-sm font-medium text-gray-700 mb-1">
                        工作时间段
                      </label>
                      <div className="flex items-center">
                        <RangePicker
                          value={[
                            rowObj.jobStartTime
                              ? dayjs(rowObj.jobStartTime)
                              : "",
                            rowObj.jobEndTime ? dayjs(rowObj.jobEndTime) : "",
                          ]}
                          style={{ width: "100%" }}
                          onChange={(dates, dateStrings) => {
                            // console.log('==>', dates,', ',  dateStrings)
                            let nextArr = [...workExperienceArr];
                            nextArr[index].jobStartTime = dateStrings[0];
                            nextArr[index].jobEndTime = dateStrings[1];
                            setWorkExperienceArr(nextArr);
                          }}
                          format={DateFormat}
                        />
                      </div>
                      <div className="flex items-center mt-2">
                        <Switch
                          value={rowObj.isCurrentEmployed == 1}
                          onChange={(val) => {
                            // console.log('switch=>', val)
                            let nextArr = [...workExperienceArr];
                            if (val) {
                              nextArr[index].isCurrentEmployed = 1;
                            } else {
                              nextArr[index].isCurrentEmployed = 0;
                            }
                            setWorkExperienceArr(nextArr);
                          }}
                        />
                        <span className="text-sm text-gray-700">
                          我目前在职
                        </span>
                      </div>
                    </div>
                    <div className="md:col-span-2">
                      <label className="block text-sm font-medium text-gray-700 mb-1">
                        工作描述
                      </label>
                      <div className="border border-gray-300 rounded overflow-hidden">
                        <TextArea
                          rows={4}
                          value={rowObj.jobDescription}
                          placeholder="请描述您的工作职责和成就"
                          onChange={(ev) => {
                            let nextArr = [...workExperienceArr];
                            nextArr[index].jobDescription =
                              ev.target.value.trim();
                            setWorkExperienceArr(nextArr);
                          }}
                        />
                      </div>
                    </div>
                  </div>
                  <div className="flex justify-end mt-3">
                    {workExperienceArr.length > 1 && (
                      <button
                        type="button"
                        className="flex items-center px-3 py-1 text-sm text-red-500 hover:text-red-700"
                        onClick={() => {
                          let nextArr = [...workExperienceArr];
                          nextArr.splice(index, 1);
                          setWorkExperienceArr(nextArr);
                        }}
                      >
                        删除
                      </button>
                    )}
                  </div>
                </div>
              ))}
              <button
                type="button"
                className="flex items-center px-4 py-2 text-primary border border-primary rounded-button hover:bg-primary/5 whitespace-nowrap"
                onClick={() => {
                  let nextArr = [...workExperienceArr];
                  nextArr.push({
                    keyId: crypto.randomUUID(),
                    companyName: "",
                    jobPosition: "",
                    jobStartTime: "",
                    jobEndTime: "",
                    jobDescription: "",
                    isCurrentEmployed: 0,
                  });
                  setWorkExperienceArr(nextArr);
                }}
              >
                添加工作经历
              </button>
            </div>
          </Form>
          <div className="fixed bottom-0 left-0 right-0 bg-white shadow-lg border-t border-gray-200 p-4">
            <div className="max-w-4xl mx-auto flex justify-between">
              <button
                type="button"
                className="hidden px-6 py-2 border border-gray-300 text-gray-700 bg-white rounded-button hover:bg-gray-50 whitespace-nowrap"
              >
                保存草稿
              </button>
              <div className="flex space-x-3">
                <button
                  type="button"
                  className="hidden px-6 py-2 border border-gray-300 text-gray-700 bg-white rounded-button hover:bg-gray-50 whitespace-nowrap"
                >
                  预览
                </button>
                <Form.Item>
                  <Button
                    onClick={() => {
                      (async () => {
                        // 基本信息
                        if (!avartarUrl) {
                          // messageApi.open({
                          //   type: "error",
                          //   content: "请上传头像",
                          // });
                          // ji_beng_xingxiRef.current.scrollIntoView()
                          // return;
                        }
                        // attachmentUrl
                        if (!userName) {
                          messageApi.open({
                            type: "error",
                            content: "姓名必填",
                          });
                          ji_beng_xingxiRef.current.scrollIntoView();
                          return;
                        }

                        // if( gender !== 0 || gender !== 1 ){
                        //   messageApi.open({
                        //     type: "error",
                        //     content: "请选择性别",
                        //   });
                        //   ji_beng_xingxiRef.current.scrollIntoView()
                        //   return;
                        // }

                        if (!birthDate) {
                          messageApi.open({
                            type: "error",
                            content: "请选择出生年月",
                          });
                          ji_beng_xingxiRef.current.scrollIntoView();
                          return;
                        }

                        if (!mobile) {
                          messageApi.open({
                            type: "error",
                            content: "请填写联系电话",
                          });
                          ji_beng_xingxiRef.current.scrollIntoView();
                          return;
                        }

                        if (!email) {
                          messageApi.open({
                            type: "error",
                            content: "请填写电子邮箱",
                          });
                          ji_beng_xingxiRef.current.scrollIntoView();
                          return;
                        }

                        if (
                          !/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(
                            email
                          )
                        ) {
                          messageApi.open({
                            type: "error",
                            content: "电子邮箱格式不正确",
                          });
                          ji_beng_xingxiRef.current.scrollIntoView();
                          return;
                        }

                        if (!jobPosition) {
                          messageApi.open({
                            type: "error",
                            content: "请填写应聘岗位",
                          });
                          ji_beng_xingxiRef.current.scrollIntoView();
                          return;
                        }

                        if (!workingYears) {
                          messageApi.open({
                            type: "error",
                            content: "请填写工作经验",
                          });
                          ji_beng_xingxiRef.current.scrollIntoView();
                          return;
                        }

                        // 求职意向
                        for (let r = 0; r < expectedJobArr.length; r++) {
                          if (!expectedJobArr[r].expectedJobTitle) {
                            messageApi.open({
                              type: "error",
                              content: "请填写期望职位",
                            });
                            qiuzhi_yixiangRef.current.scrollIntoView();
                            return;
                          }

                          if (!expectedJobArr[r].expectedJobSalaryRange) {
                            messageApi.open({
                              type: "error",
                              content: "请选择期望薪资",
                            });
                            qiuzhi_yixiangRef.current.scrollIntoView();
                            return;
                          }

                          if (!expectedJobArr[r].expectedJobLocation) {
                            messageApi.open({
                              type: "error",
                              content: "请填写期望城市",
                            });
                            qiuzhi_yixiangRef.current.scrollIntoView();
                            return;
                          }

                          if (!expectedJobArr[r].expectedJobCategory) {
                            messageApi.open({
                              type: "error",
                              content: "请选择工作类型",
                            });
                            qiuzhi_yixiangRef.current.scrollIntoView();
                            return;
                          }
                        } // for r

                        // 教育经历
                        for (let r = 0; r < userEducationArr.length; r++) {
                          if (!userEducationArr[r].schoolName) {
                            messageApi.open({
                              type: "error",
                              content: "请填写学校名称",
                            });
                            jiaoyuRef.current.scrollIntoView();
                            return;
                          }

                          if (!userEducationArr[r].majorName) {
                            messageApi.open({
                              type: "error",
                              content: "请填写专业名称",
                            });
                            jiaoyuRef.current.scrollIntoView();
                            return;
                          }

                          if (!userEducationArr[r].educationLevel) {
                            messageApi.open({
                              type: "error",
                              content: "请选择学历",
                            });
                            jiaoyuRef.current.scrollIntoView();
                            return;
                          }

                          if (!userEducationArr[r].enrollmentDate) {
                            messageApi.open({
                              type: "error",
                              content: "请选择入学时间与毕业时间",
                            });
                            jiaoyuRef.current.scrollIntoView();
                            return;
                          }
                        } // for r

                        // 工作经历
                        for (let r = 0; r < workExperienceArr.length; r++) {
                          if (!workExperienceArr[r].companyName) {
                            messageApi.open({
                              type: "error",
                              content: "请填写公司名称",
                            });
                            gongzuoRef.current.scrollIntoView();
                            return;
                          }

                          if (!workExperienceArr[r].jobPosition) {
                            messageApi.open({
                              type: "error",
                              content: "请填写职位名称",
                            });
                            gongzuoRef.current.scrollIntoView();
                            return;
                          }

                          if (!workExperienceArr[r].jobStartTime) {
                            messageApi.open({
                              type: "error",
                              content: "请选择工作时间段",
                            });
                            gongzuoRef.current.scrollIntoView();
                            return;
                          }
                        } // for r

                        // 附件简历
                        if (!wordPdfUrl) {
                          messageApi.open({
                            type: "error",
                            content: "请上传附件简历",
                          });
                          return;
                        }

                        // 最终提交
                        // -- 基本信息
                        setLoading(true);
                        try {
                          let res1 = await postUserEdit({
                            id: user.id,
                            loginBizId: user.loginBizId,
                            userName: userName,
                            mobile: mobile,
                            email: email,
                            gender: gender,
                            birthDate: birthDate,
                            wechatId: wechatId,
                            avatarUrl: avartarUrl,
                            jobPosition: jobPosition,
                            workingYears: workingYears,
                            attachmentUrl: wordPdfUrl,
                          });

                          ctx.login(res1.result);

                          console.log("res1=", res1);
                          // 求职意向
                          let params2 = expectedJobArr
                            .map((rowObj) => ({ ...rowObj }))
                            .map((rowObj) => {
                              rowObj.loginBizId = user.loginBizId;
                              rowObj.userType = user.userType;
                              delete rowObj.keyId;
                              return rowObj;
                            });
                          let res2 = await postAddExpectedJob(params2);
                          console.log("res2=", res2);

                          // 教育经验
                          let params3 = userEducationArr
                            .map((rowObj) => ({ ...rowObj }))
                            .map((rowObj) => {
                              rowObj.loginBizId = user.loginBizId;
                              rowObj.userType = user.userType;
                              delete rowObj.keyId;
                              return rowObj;
                            });

                          let res3 = await postAddUserEducation(params3);
                          console.log("res3=", res3);

                          // 工作经历
                          let params4 = workExperienceArr
                            .map((rowObj) => ({ ...rowObj }))
                            .map((rowObj) => {
                              rowObj.loginBizId = user.loginBizId;
                              rowObj.userType = user.userType;
                              delete rowObj.keyId;
                              return rowObj;
                            });

                          let res4 = await postAddUserWorkExperience(params4);
                          console.log("res4=", res4);

                          messageApi.open({
                            type: "success",
                            content: "编辑资料成功",
                          });
                          setTimeout(() => {
                            navigate(-1);
                          }, 1000);
                        } catch (e) {
                          console.log(e);
                        } finally {
                          setTimeout(() => {
                            setLoading(false);
                          }, 800);
                        }
                      })();
                    }}
                    type="primary"
                    htmlType="submit"
                  >
                    发布简历
                  </Button>
                </Form.Item>
                <Form.Item>
                  {wordPdfUrl ? (
                    <>
                      <Popconfirm
                        trigger="hover"
                        title=""
                        overlayStyle={{ width: "400px" }}
                        okButtonProps={{ style: { display: "none" } }}
                        cancelButtonProps={{ style: { display: "none" } }}
                        description={wordPdfUrl}
                      >
                        <FilePdfOutlined style={{ fontSize: 36 }} />
                        <span className="inline-block w-[200px] ml-2 overflow-ellipsis overflow-hidden whitespace-nowrap">
                          {wordPdfUrl.replace(/^.*\//, "")}
                        </span>
                      </Popconfirm>
                      <span
                        title="删除"
                        className="ml-4"
                        onClick={() => {
                          setWordPdfUrl("");
                        }}
                      >
                        <DeleteOutlined
                          style={{ fontSize: 20, color: "red" }}
                        />
                      </span>
                    </>
                  ) : (
                    <>
                      <input
                        type="file"
                        ref={wordInputRef}
                        accept="application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/pdf"
                        style={{ display: "none" }}
                        onChange={(ev) => {
                          handleFileUpload(ev.target.files[0], "word");
                          ev.target.value = "";
                        }}
                      />
                      <Button
                        onClick={() => {
                          wordInputRef.current.click();
                        }}
                      >
                        上传附件简历(支持word、pdf格式)
                      </Button>
                    </>
                  )}
                </Form.Item>
                {/* <button
                type="button"
                className="px-6 py-2 bg-primary text-white rounded-button hover:bg-primary/90 whitespace-nowrap"
                onClick={() => {
                  (async () => {
                    // 基本信息
                    if (!userName) {
                      messageApi.open({
                        type: "error",
                        content: "姓名必填",
                      });
                      return;
                    }
                  })();
                }}
              >
                发布简历
              </button> */}
              </div>
            </div>
          </div>
        </div>
      </div>
    </Spin>
  );
};
